//
//  HNSH_TZExchangeTopView.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/6/14.
//

#import "HNSH_TZExchangeTopView.h"

#import "HNSH_WithdrawalViewController.h"

@interface HNSH_TZExchangeTopView ()

/* bgView */
@property (nonatomic, strong) UIImageView *bgView;

/* centerTitleLabel */
@property (nonatomic, strong) UILabel *centerTitleLabel;
/* centerLabel */
@property (nonatomic, strong) UILabel *centerLabel;

/* button */
@property (nonatomic, strong) UIButton *button;

@end

@implementation HNSH_TZExchangeTopView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor appBGColor];
        [self configUI];
    }
    return self;
}

- (void)configType:(NSInteger)type infoModel:(HNSH_TZExchangeModel *)infoModel {
    _type = type;
    _infoModel = infoModel;
    self.button.hidden = type == 2;
    if (type == 2) {
        self.centerLabel.text = infoModel.frozen_integral;
        self.centerTitleLabel.text = @"冻结能量";
    } else {
        self.centerLabel.text = infoModel.cash_balance;
        self.centerTitleLabel.text = @"现金余额";
    }
}

- (void)configUI {
    [self addSubview:self.bgView];
    
    [self.bgView addSubview:self.centerTitleLabel];
    [self.bgView addSubview:self.centerLabel];
    [self.bgView addSubview:self.button];
}

#pragma mark lazy
- (UIImageView *)bgView {
    if (!_bgView) {
        _bgView = [[UIImageView alloc]initWithFrame:CGRectMake(12, 12, kScreenWidth-24, 89)];
        _bgView.image = [UIImage imageNamed:@"tz_exchange_top_bg"];
        _bgView.userInteractionEnabled = YES;
    }
    return _bgView;
}

- (UILabel *)centerTitleLabel {
    if (!_centerTitleLabel) {
        _centerTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 20, 200, 17)];
        _centerTitleLabel.text = @"余额";
        _centerTitleLabel.textColor = [UIColor colorWithHexString:@"#FFE5E3"];
        _centerTitleLabel.font = [UIFont systemFontOfSize:12];
    }
    return _centerTitleLabel;
}

- (UILabel *)centerLabel {
    if (!_centerLabel) {
        _centerLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 39, 200, 30)];
        _centerLabel.text = @"12004.32";
        _centerLabel.textColor = [UIColor whiteColor];
        _centerLabel.font = [UIFont boldSystemFontOfSize:22];
    }
    return _centerLabel;
}

- (UIButton *)button {
    if (!_button) {
        _button = [UIButton buttonWithType:UIButtonTypeCustom];
        _button.frame = CGRectMake(self.bgView.width-100, 29, 80, 32);
        [_button setTitle:@"提现" forState:UIControlStateNormal];
        [_button setTitleColor:[UIColor appGreenColor] forState:UIControlStateNormal];
        _button.titleLabel.font = [UIFont boldSystemFontOfSize:16];
        _button.backgroundColor = [UIColor appWhiteLabelColor];
        _button.layer.cornerRadius = 16.0f;
        _button.layer.masksToBounds = YES;
        [[_button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            HNSH_WithdrawalViewController *vc = [[HNSH_WithdrawalViewController alloc]init];
            [[UIViewControllerHelper findCurrentShowingViewController].navigationController pushViewController:vc animated:YES];
        }];
    }
    return _button;
}

@end
